package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.entity.Coupon;
import com.chixing.entity.VO.myCouponDetailVO;
import com.chixing.mapper.CouponMapper;
import com.chixing.service.ICouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author smith
 * @since 2025-09-22
 */
@Service
public class CouponServiceImpl  implements ICouponService {
    @Autowired
    private CouponMapper couponMapper;

    public Result getById(Integer id){
        System.out.println(id);
        Coupon coupon = couponMapper.selectById(id);
        if(coupon !=null)
            return Result.getSuccess(coupon);
        return Result.getFail(null);
    }

    @Override
    public Result getByStatus(Integer userId,Integer couponStatus) {
        List<myCouponDetailVO> myCouponDetailVOS = couponMapper.selectAllCoupon(userId, couponStatus);
        if (myCouponDetailVOS!=null && myCouponDetailVOS.size()>0){
            return Result.getSuccess(myCouponDetailVOS);
        }
        return Result.getFail(myCouponDetailVOS) ;
    }

    @Override
    public Result getAll() {
        QueryWrapper<Coupon> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("cou_publish_time");
        List<Coupon> coupons = couponMapper.selectList(wrapper);
        if (coupons!=null && coupons.size()>0)
            return Result.getSuccess(coupons);
        return Result.getFail(null);
    }

}
